home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Complete Linux
/
Complete Linux.iso
/
xwindows
/
demos
/
xfract_1.z
/
xfract_1
/
xfractint-1.06
/
unixscr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-05
|
44KB
|
2,120 lines
/* Unixscr.c
* This file contains routines for the Unix port of fractint.
* It uses the current window for text and creates an X window for graphics.
*
* This file Copyright 1991 Ken Shirriff. It may be used according to the
* fractint license conditions, blah blah blah.
*
* Some of the X stuff is based on xloadimage by Jim Frost.
* The FindWindowRoot routine is from ssetroot by Tom LaStrange.
* Other root window stuff is based on xmartin, by Ed Kubaitis.
* Some of the colormap stuff is from Mike Yang (mikey@sgi.com).
* Some of the zoombox code is from Bill Broadley.
* David Sanderson straightened out a bunch of include file problems.
*/
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <signal.h>
#include <sys/types.h>
#ifdef _AIX
#include <sys/select.h>
#endif
#include <sys/time.h>
#include <sys/ioctl.h>
#ifdef FPUERR
#include <floatingpoint.h>
#endif
#ifdef __hpux
#include <sys/file.h>
#endif
#include <fcntl.h>
#include "fractint.h"
#include "prototyp.h"
#include "helpdefs.h"
/* Check if there is a character waiting for us. */
#define input_pending() (ioctl(0,FIONREAD,&iocount),(int)iocount)
/* external variables (set in the FRACTINT.CFG file, but findable here */
extern int dotmode; /* video access method (= 19) */
extern int sxdots, sydots; /* total # of dots on the screen */
extern int sxoffs, syoffs; /* offset of drawing area */
extern int colors; /* maximum colors available */
extern int initmode;
extern int adapter;
extern int gotrealdac;
extern int inside_help;
extern float finalaspectratio;
extern struct videoinfo videotable[];
/* the video-palette array (named after the VGA adapter's video-DAC) */
extern unsigned char dacbox[256][3];
extern void drawbox();
extern int text_type;
extern int helpmode;
extern void fpe_handler();
extern WINDOW *curwin;
static int onroot = 0;
static int fullscreen = 0;
static int sharecolor = 0;
static int privatecolor = 0;
static int fixcolors = 0;
static int rsync = 0; /* Run X events synchronously (debugging) */
int slowdisplay = 0; /* We have a slow display, so don't print too much */
static int simple_input = 0; /* Use simple input (debugging) */
static char *Xdisplay = "";
static char *Xgeometry = NULL;
static int unixDisk = 0; /* Flag if we use the disk video mode */
static int old_fcntl;
static int doesBacking;
/*
* The pixtab stuff is so we can map from fractint pixel values 0-n to
* the actual color table entries which may be anything.
*/
static int usepixtab = 0;
static unsigned long pixtab[256];
static int ipixtab[256];
static int fastmode = 0; /* Don't draw pixels 1 at a time */
static int alarmon = 0; /* 1 if the refresh alarm is on */
static int doredraw = 0; /* 1 if we have a redraw waiting */
/* Static routines */
static Window FindRootWindow(void);
static Window pr_dwmroot(Display *dpy, Window pwin);
static int errhand(Display *dp, XErrorEvent *xe);
static int getachar(void);
static int handleesc(void);
static int translatekey(int ch);
static int xcmapstuff(void);
static int xhandleevents(void);
static void RemoveRootPixmap(void);
static void doneXwindow(void);
static void initdacbox(void);
static void setredrawscreen(void);
static void clearXwindow(void);
#ifdef FPUERR
static void continue_hdl(int sig, int code, struct sigcontext *scp,
char *addr);
#endif
/*
*----------------------------------------------------------------------
*
* unixarg --
*
* See if we want to do something with the argument.
*
* Results:
* Returns 1 if we parsed the argument.
*
* Side effects:
* Increments i if we use more than 1 argument.
*
*----------------------------------------------------------------------
*/
int
unixarg(argc,argv,i)
int argc;
char **argv;
int *i;
{
if (strcmp(argv[*i],"-display")==0 && (*i)+1<argc) {
Xdisplay = argv[(*i)+1];
(*i)++;
return 1;
} else if (strcmp(argv[*i],"-fullscreen")==0) {
fullscreen = 1;
return 1;
} else if (strcmp(argv[*i],"-disk")==0) {
unixDisk = 1;
return 1;
} else if (strcmp(argv[*i],"-onroot")==0) {
onroot = 1;
return 1;
} else if (strcmp(argv[*i],"-share")==0) {
sharecolor = 1;
return 1;
} else if (strcmp(argv[*i],"-fast")==0) {
fastmode = 1;
return 1;
} else if (strcmp(argv[*i],"-simple")==0) {
simple_input = 1;
return 1;
} else if (strcmp(argv[*i],"-slowdisplay")==0) {
slowdisplay = 1;
return 1;
} else if (strcmp(argv[*i],"-sync")==0) {
rsync = 1;
return 1;
} else if (strcmp(argv[*i],"-private")==0) {
privatecolor = 1;
return 1;
} else if (strcmp(argv[*i],"-fixcolors")==0 && *i+1<argc) {
fixcolors = atoi(argv[(*i)+1]);
(*i)++;
return 1;
} else if (strcmp(argv[*i],"-geometry")==0 && *i+1<argc) {
Xgeometry = argv[(*i)+1];
(*i)++;
return 1;
} else {
return 0;
}
}
/*
*----------------------------------------------------------------------
*
* UnixInit --
*
* Initialize the windows and stuff.
*
* Results:
* None.
*
* Side effects:
* Initializes windows.
*
*----------------------------------------------------------------------
*/
void
UnixInit()
{
/*
* Check a bunch of important conditions
*/
if (sizeof(short) != 2) {
fprintf(stderr,"Error: need short to be 2 bytes\n");
exit(-1);
}
if (sizeof(long) != sizeof(FLOAT4)) {
fprintf(stderr,"Error: need sizeof(long)=sizeof(FLOAT4)\n");
exit(-1);
}
initscr();
curwin = stdscr;
cbreak();
noecho();
if (standout()) {
text_type = 1;
standend();
} else {
text_type = 1;
}
signal(SIGINT,goodbye);
signal(SIGFPE, fpe_handler);
/*
signal(SIGTSTP,goodbye);
*/
#ifdef FPUERR
signal(SIGABRT,SIG_IGN);
/*
setup the IEEE-handler to forget all common ( invalid,
divide by zero, overflow ) signals. Here we test, if
such ieee trapping is supported.
*/
if (ieee_handler("set","common",continue_hdl) != 0 )
printf("ieee trapping not supported here \n");
#endif
}
/*
*----------------------------------------------------------------------
*
* UnixDone --
*
* Cleanup windows and stuff.
*
* Results:
* None.
*
* Side effects:
* Cleans up.
*
*----------------------------------------------------------------------
*/
void
UnixDone()
{
if (!unixDisk) {
doneXwindow();
}
if (!simple_input) {
fcntl(0,F_SETFL,old_fcntl);
}
mvcur(0,COLS-1, LINES-1,0);
nocbreak();
echo();
endwin();
}
/*
*----------------------------------------------------------------------
*
* errhand --
*
* Called on an X server error.
*
* Results:
* None.
*
* Side effects:
* Prints the error message.
*
*----------------------------------------------------------------------
*/
static int errhand(dp,xe)
Display *dp;
XErrorEvent *xe;
{
char buf[200];
fflush(stdout);
printf("X Error: %d %d %d %d\n",xe->type,xe->error_code,
xe->request_code, xe->minor_code);
XGetErrorText(dp,xe->error_code,buf,200);
printf("%s\n",buf);
}
#ifdef FPUERR
/*
*----------------------------------------------------------------------
*
* continue_hdl --
*
* Handle an IEEE fpu error.
* This routine courtesy of Ulrich Hermes
* <hermes@olymp.informatik.uni-dortmund.de>
*
* Results:
* None.
*
* Side effects:
* Clears flag.
*
*----------------------------------------------------------------------
*/
static void
continue_hdl(sig,code,scp,addr)
int sig, code;
struct sigcontext *scp;
char *addr;
{
int i;
char out[20];
/* if you want to get all messages enable this statement. */
/* printf("ieee exception code %x occurred at pc %X\n",code,scp->sc_pc); */
/* clear all excaption flags */
i = ieee_flags("clear","exception","all",out);
}
#endif
#define DEFX 640
#define DEFY 480
#define DEFXY "640x480+0+0"
static Display *Xdp = NULL;
static Window Xw;
static GC Xgc = NULL;
static Visual *Xvi;
static Screen *Xsc;
static Colormap Xcmap;
static int Xdepth;
static XImage *Ximage =NULL;
static char *Xdata;
static int Xdscreen;
static Pixmap Xpixmap = 0;
static int Xwinwidth=DEFX,Xwinheight=DEFY;
static Win